package com.cloudcc.mobile.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView.Adapter;
import android.support.v7.widget.RecyclerView.ViewHolder;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cloudcc.mobile.R;
import com.cloudcc.mobile.adapter.BusinesscardAdapter.MyViewHolder;

public class BusinesscardAdapter extends Adapter<MyViewHolder> {
	private Context mContext;
	private LayoutInflater mLayoutInflater;

	private OnMyClickListener mOnClickListener;

	private   String[] titles = null;

	private static final int[] resIds = new int[] {
			R.drawable.ico_customer_hide, R.drawable.ico_customer_lx,R.drawable.scan_login };

	public BusinesscardAdapter(Context mContext) {
		super();
		this.mContext = mContext;
		mLayoutInflater = LayoutInflater.from(mContext);
		titles = new String[]{mContext.getString(R.string.baocunqianke),
				mContext.getString(R.string.baocunkehu) ,mContext.getString(R.string.saoma)};
	}

	@Override
	public MyViewHolder onCreateViewHolder(ViewGroup arg0, int arg1) {
		View view = mLayoutInflater
				.inflate(R.layout.item_business, null, false);
		MyViewHolder holder = new MyViewHolder(view);
		return holder;
	}

	@Override
	public int getItemCount() {
		return 3;
	}

	@Override
	public void onBindViewHolder(MyViewHolder holder, int arg1) {
		String title = titles[arg1];
		holder.title.setText(title);
		holder.iv1.setImageResource(resIds[arg1]);
		final int pos = arg1;
		holder.mCardView.setOnClickListener(new OnClickListener() {

			@Override
			public void onClick(View v) {
				if (mOnClickListener != null) {
					mOnClickListener.onClickItem(pos);
				}
			}
		});
	}

	public void setOnClickItemlistener(OnMyClickListener l) {
		this.mOnClickListener = l;
	}

	public interface OnMyClickListener {

		void onClickItem(int pos);
	}

	public class MyViewHolder extends ViewHolder {

		ImageView iv1;
		TextView title;

		RelativeLayout mCardView;

		public MyViewHolder(View view) {
			super(view);
			iv1 = (ImageView) view.findViewById(R.id.iv1);
			title = (TextView) view.findViewById(R.id.tv1);
			mCardView = (RelativeLayout) view.findViewById(R.id.card_view);
		}

	}

}
